<?php
require(dirname(dirname(__FILE__))."/Config/config.php");
require(dirname(dirname(__FILE__))."/jssdk.php");
class reporterController extends appController{
    
    public function index()
    {
        $this->check_member();
        $m = Model("reporter");
        $reporter_id = $_GET['id'];
        $status = yf_empty($_GET['status'],1,true);
        $info = $m -> get_new($reporter_id,$status);
        $this->assign("info", $info);
        $this->assign("status", $info['status']);
        $m -> insertUVPV(1,$info['id']);
        //微信分享参数构建
        $jsdk = $m ->get_jsdk();
        $this->assign("jsdk", $jsdk);
        $this->assign_global();
        if($info['is_live']>0){
            $this->display("live.html");
        }else{
            $this->assign("tabs", $m -> getTab($reporter_id));
            $this->display("reporter.html");
        }
    }
    
    public function preview()
    {
        $this->check_member();
        $m = Model("reporter");
        $new_id = $_GET['new_id'];
        $info = $m -> get_new_info($new_id);
        $this->assign("info", $info);
        $this->assign("status", $info['status']);
        $m -> insertUVPV(1,$info['id']);
        //微信分享参数构建
        $jsdk = $m ->get_jsdk();
        $this->assign("jsdk", $jsdk);
        $this->assign_global();
        if($info['type']>0){
            $this->display("live.html");
        }else{
            $this->assign("tabs", $m -> getTab($info['reporter_id']));
            $this->display("reporter.html");
        }
    }
    
    
    public function zan()
    {
        $wxid = yf_empty($_SESSION['wxid'],"请重新登录后再点赞");
        $new_id = yf_empty($_REQUEST['new_id'],"请刷新页面后重新登录");
        $result = Model('reporter')->zan($wxid,$new_id);
        $result['error'] = 0;
        $this->showMsg($result);
    }
    
    public function sendComment()
    {
        $wxid = yf_empty($_SESSION['wxid'],"请重新登录后再评论");
        $comment = yf_empty($_REQUEST["comment"],"请说几句吧，谢谢~");
        $new_id = yf_empty($_REQUEST["new_id"],"请刷新后重新登录吧，谢谢~");
        $result = Model('reporter')->sendComment($wxid,$comment,$new_id);
        $this->showMsg($result);
    }
    
    
    public function getHomeInfo()
    {
        $m = Model('reporter');
        $res = $m->getHomeInfo();
        die($_REQUEST['callback']."(".json_encode($res).")");
    }
}